package com.sskj.mine;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.asset.data.CoinTypeBean;
import com.sskj.mine.bean.BuyBalanceBean;
import com.sskj.mine.bean.PayWayBean;
import com.sskj.mine.bean.PayWayListBean;
import com.sskj.mine.bean.PlatFormBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;

import java.util.List;

public class BuyPresenter extends BasePresenter<BuyActivity> {

    public void getBalance(String type) {
        OkGo.<HttpData<BuyBalanceBean>>post(HttpConfig.BASE_URL + HttpConfig.BUY_BALANCE)
                .params("code", type)
                .execute(new JsonCallBack<HttpData<BuyBalanceBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<BuyBalanceBean>> response) {
                        HttpData body = response.body();
                        if (body.status == HttpConfig.OK) {
                            mView.updateUi(response.body().getData());
                        }
                    }
                });
    }

    /**
     *
     */
    public void rj() {
        OkGo.<HttpData<BuyBalanceBean>>post(HttpConfig.BASE_URL + HttpConfig.BUY_BALANCE)
                .params("code", "btc_usdt")
                .execute(new JsonCallBack<HttpData<BuyBalanceBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<BuyBalanceBean>> response) {
                        HttpData body = response.body();
                        if (body.status == HttpConfig.OK) {
                            mView.updateUi(response.body().getData());
                        }
                    }
                });
    }

    public void getAllCoin(boolean isCreate) {
        httpService.getAllCoinInfo(isCreate)
                .execute(new JsonCallBack<HttpData<List<CoinTypeBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<CoinTypeBean>>> response) {
                        HttpData<List<CoinTypeBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateCoinType(httpData.getData());
                        }
                    }
                });
    }

    public void requsetPayWayList() {
        OkGo.<HttpData<List<PayWayListBean>>>get(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_LIST)
                .params("account", SPUtil.get(SPConfig.ACCOUNT, ""))
                .execute(new JsonCallBack<HttpData<List<PayWayListBean>>>(this, false) {
                    @Override
                    public void onSuccess(Response<HttpData<List<PayWayListBean>>> response) {
                        if (response.body().getStatus() == HttpConfig.OK) {
                            mView.updatePayUi(response.body().getData());
                        }
                    }
                });
    }

    public void requsetPlatformInfo() {
        OkGo.<HttpData<PlatFormBean>>get(HttpConfig.BASE_URL + HttpConfig.PLATFORMINFO)
                .execute(new JsonCallBack<HttpData<PlatFormBean>>(this, false) {
                    @Override
                    public void onSuccess(Response<HttpData<PlatFormBean>> response) {
                        if (response.body().getStatus() == HttpConfig.OK) {
                            mView.updatePlatformInfo(response.body().getData());
                        }
                    }
                });
    }

    public void Buy(String price, String img, String pid, String bankid, String banktp, String type) {
        OkGo.<HttpData<PayWayListBean>>get(HttpConfig.BASE_URL + HttpConfig.BUY)
                .params("price", price)
                .params("img", img)
                .params("pid", pid)
                .params("bankid", bankid)
                .params("banktp", banktp)
                .params("type", type)
                .execute(new JsonCallBack<HttpData<PayWayListBean>>(this, false) {
                    @Override
                    public void onSuccess(Response<HttpData<PayWayListBean>> response) {
                        if (response.body().getStatus() == HttpConfig.OK) {
                            ToastUtil.showShort(response.message());
                            mView.updateBuyUi();
                        }
                    }
                });
    }
}
